package org.example.springblog.config;

import lombok.extern.slf4j.Slf4j;
import org.example.springblog.model.Result;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ErrorHandler  {
    //如果程序发生异常的话，程序直接跳转到这个地方
    @ExceptionHandler
    public Result handlerError(Exception e) {
        log.info("发生异常");
        return Result.fail(e.getMessage());
    }
}
